package com.roadrunner;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import android.content.Context;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonController
{
	private ObjectMapper objectMapper = null;
	private JsonFactory jsonFactory = null;
	private JsonParser jp = null;    
	    
	public JsonController()
	{
		objectMapper = new ObjectMapper();
		jsonFactory = new JsonFactory();
	}
	 
	public ArrayList<Job> parseOrders(String jsontext)
	{
		ArrayList<Job> orders = new ArrayList<Job>();
		Job myOrder = null;
	    	
		try 
		{
			jp = jsonFactory.createJsonParser(jsontext);
			jp.nextToken();
		           
			while (jp.nextToken() == JsonToken.START_OBJECT)
			{
				myOrder = objectMapper.readValue(jp, Job.class);
				orders.add(myOrder);
			}
		} 
		catch (JsonParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	                
		return orders;
	}
}
